package com.collabscm.pf;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Locale;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

import com.collabscm.pf.Preloader;
import com.collabscm.pf.logging.Logger;
import com.collabscm.pf.logging.LoggerFactory;

/**
 * 系统抽象的TestCase类
 *
 * @author Zeng Raoxing
 */
public class AbstractTestCase extends AbstractTransactionalJUnit4SpringContextTests {
	static {
		new Preloader().load("preload-config.xml");
	}

	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	public abstract static class MockResponse implements HttpServletResponse {

		@Override
		public void addCookie(Cookie cookie) {
			
		}

		@Override
		public void addDateHeader(String name, long date) {
			
		}

		@Override
		public void addHeader(String name, String value) {
			
		}

		@Override
		public void addIntHeader(String name, int value) {
			
		}

		@Override
		public boolean containsHeader(String name) {
			return false;
		}

		@Override
		public String encodeRedirectURL(String url) {
			return null;
		}

		@Override
		public String encodeRedirectUrl(String url) {
			return null;
		}

		@Override
		public String encodeURL(String url) {
			return null;
		}

		@Override
		public String encodeUrl(String url) {
			return null;
		}

		@Override
		public void sendError(int sc) throws IOException {
			
		}

		@Override
		public void sendError(int sc, String msg) throws IOException {
			
		}

		@Override
		public void sendRedirect(String location) throws IOException {
			
		}

		@Override
		public void setDateHeader(String name, long date) {
			
		}

		@Override
		public void setHeader(String name, String value) {
			
		}

		@Override
		public void setIntHeader(String name, int value) {
			
		}

		@Override
		public void setStatus(int sc) {
			
		}

		@Override
		public void setStatus(int sc, String sm) {
			
		}

		@Override
		public void flushBuffer() throws IOException {
			
		}

		@Override
		public int getBufferSize() {
			return 0;
		}

		@Override
		public String getCharacterEncoding() {
			return null;
		}

		@Override
		public String getContentType() {
			return null;
		}

		@Override
		public Locale getLocale() {
			return null;
		}

		@Override
		public ServletOutputStream getOutputStream() throws IOException {
            ServletOutputStream sos = new ServletOutputStream(){
				@Override
				public void write(int b) throws IOException {
					System.out.print(b + ",");
				}
			};
            return sos;
		}

		@Override
		public PrintWriter getWriter() throws IOException {
			return null;
		}

		@Override
		public boolean isCommitted() {
			return false;
		}

		@Override
		public void reset() {
			
		}

		@Override
		public void resetBuffer() {
			
		}

		@Override
		public void setBufferSize(int size) {
			
		}

		@Override
		public void setCharacterEncoding(String charset) {
			
		}

		@Override
		public void setContentLength(int len) {
			
		}

		@Override
		public void setContentType(String type) {
			
		}

		@Override
		public void setLocale(Locale loc) {
			
		}
		
	}
	
}
